package cn.homj.autogen4j.support;

import java.util.List;

import com.alibaba.fastjson2.annotation.JSONField;

import cn.homj.autogen4j.support.openai.chat.ToolCall;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author jiehong.jh
 * @date 2023/11/22
 */
@Data
@Accessors(chain = true)
public class Message implements Cloneable {
    /**
     * An optional name for the participant.
     */
    private String name;
    /**
     * The role of the author of this message.
     */
    private String role;
    /**
     * The contents of the message.
     */
    private String content;
    /**
     * Tool call that this message is responding to.
     */
    @JSONField(name = "tool_call_id")
    private String toolCallId;
    /**
     * The tool calls generated by the model, such as function calls.
     */
    @JSONField(name = "tool_calls")
    private List<ToolCall> toolCalls;

    @Override
    public Message clone() {
        try {
            return (Message)super.clone();
        } catch (CloneNotSupportedException e) {
            // unreachable
            throw new IllegalStateException(e);
        }
    }

    public static Message ofSystem(String content) {
        Message message = new Message();
        message.role = "system";
        message.content = content;
        return message;
    }

    public static Message ofUser(String content) {
        Message message = new Message();
        message.role = "user";
        message.content = content;
        return message;
    }

    public static Message ofAssistant(String content) {
        Message message = new Message();
        message.role = "assistant";
        message.content = content;
        return message;
    }

    public static Message ofTool(String result, String toolCallId) {
        Message message = new Message();
        message.role = "tool";
        message.content = result;
        message.toolCallId = toolCallId;
        return message;
    }
}
